var power_permissions_ops={
    init:function(){
        this.eventBind();
    },

    eventBind:function(){
        //删除权限按钮
        $('.delete').click(function(){
            var id=$(this).attr('data-delete-id');
            var title=$(this).attr('data-delete-title');
            layer.confirm('是否删除-'+title+'?',{
                btn:['删除','取消']
            },function(){
                //ajax
                $.ajax({
                    url:'/admin/permissions/delete',
                    method:'post',
                    data:{
                        id:id
                    },
                    dataType:'json',
                    success:function(res){
                        var callback=null;

                        if(res.code == 200){
                            callback=function(){
                                window.location.href=window.location.href;
                            }
                        }

                        common_ops.alert(res.msg,callback);
                    }
                })
            });
        });

        //恢复权限按钮
        $('.recover').click(function(){
            var id=$(this).attr('data-recover-id');
            var title=$(this).attr('data-recover-title');

            layer.confirm('是否恢复-'+title+'?',{
                btn:['恢复','取消']
            },function(){
                $.ajax({
                    url:'/admin/permissions/recover',
                    method:'post',
                    data:{
                        id:id
                    },
                    dataType:'json',
                    success:function(res){
                        var callback=null;

                        if(res.code == 200){
                            callback=function(){
                                window.location.href=window.location.href;
                            }
                        }

                        common_ops.alert(res.msg,callback);
                    }
                })
            })
        })
    }
};

$(document).ready(function(){
    layer.config({
        skin:'layui-layer-lan',
        offset:'200px'
    });
    power_permissions_ops.init()
});